//本项目使用的api接口统一在此管理

//api的基地址
export function getBaseUrl() {
    return "./rms/"
}
//文件上传的基地址
export function getMappingUploadBaseUrl() {
    return getBaseUrl() + "api/retrace/upload/mapping/"
}


//翻译日志(通过mappingId)
export function retraceByMappingId(
    mappingId,//string,mapping文件的标识
    willRetraceLog,//string,待翻译的日志
    verbose,
    allClassNames

) {
    var myHeaders = new Headers();
    myHeaders.append("Content-Type", "application/json");

    var requestOptions = {
        method: "POST",
        headers: myHeaders,
        body: JSON.stringify({
            stackTraceText: willRetraceLog,
            verbose: verbose,
            allClassNames: allClassNames
        }),
        redirect: "follow",
    };

    return fetch(
        getBaseUrl() + "api/retrace/mapping/" + mappingId,
        requestOptions
    )
        .then((response) => response.json())
}
//翻译日志(通过url)
export function retraceByUrl(
    mappingUrl,//string,mapping文件在线可访问链接地址
    willRetraceLog,//string,待翻译的日志
    verbose,
    allClassNames

) {
    var myHeaders = new Headers();
    myHeaders.append("Content-Type", "application/json");

    var requestOptions = {
        method: "POST",
        headers: myHeaders,
        body: JSON.stringify({
            mappingUrl: mappingUrl,
            stackTraceText: willRetraceLog,
            verbose: verbose,
            allClassNames: allClassNames
        }),
        redirect: "follow",
    };

    return fetch(
        getBaseUrl() + "api/retrace/mapping/url",
        requestOptions
    )
        .then((response) => response.json())

}

//获得文件上传的url
export function getMappingUploadUrl(
    mappingId//string,mapping文件的标识
) {
    return getMappingUploadBaseUrl() + mappingId
}